package com.bianmaba.wdc.service;

import com.bianmaba.spring.supports.service.BaseService;
import com.bianmaba.wdc.bean.entity.Holiday;
import com.bianmaba.wdc.repository.HolidayRepository;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by cwx183898 on 2017/12/14.
 */
@Service
@Transactional
public class HolidayService extends BaseService<Holiday, String> implements IHolidayService {
    private static final Log LOG = LogFactory.getLog(HolidayService.class);
    @Autowired
    private HolidayRepository repository;

    @Override
    public HolidayRepository getRepository() {
        return repository;
    }

    @Override
    public <S extends Holiday> S save(S entity) {
        if (entity.getStartDate().getTime() > entity.getEndDate().getTime()) {
            return null;
        }
        Date tmp = DateUtils.addDays(entity.getEndDate(), 1);
        tmp = DateUtils.addSeconds(tmp, -1);
        entity.setEndDate(tmp);
        return super.save(entity);
    }
}
